home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / lock.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  2.2 KB  |  98 lines  |  [TEXT/ttxt]

  1. #
  2. # Testing of table locking
  3. #
  4.  
  5. drop table if exists t1,t2;
  6. CREATE TABLE t1 (  `id` int(11) NOT NULL default '0', `id2` int(11) NOT NULL default '0', `id3` int(11) NOT NULL default '0', `dummy1` char(30) default NULL, PRIMARY KEY  (`id`,`id2`), KEY `index_id3` (`id3`)) TYPE=MyISAM;
  7. insert into t1 (id,id2) values (1,1),(1,2),(1,3);
  8. LOCK TABLE t1 WRITE;
  9. select dummy1,count(distinct id) from t1 group by dummy1;
  10. update t1 set id=-1 where id=1;
  11. LOCK TABLE t1 READ;
  12. --error 1099
  13. update t1 set id=1 where id=1;
  14. --error 1100
  15. create table t2 SELECT * from t1;
  16. create temporary table t2 SELECT * from t1;
  17. drop table if exists t2;
  18. unlock tables;
  19. create table t2 SELECT * from t1;
  20. LOCK TABLE t1 WRITE,t2 write;
  21. insert into t2 SELECT * from t1;
  22. update t1 set id=1 where id=-1;
  23. drop table t1,t2;
  24.  
  25.  
  26. #
  27. # Check bug with INSERT ... SELECT with lock tables
  28. #
  29.  
  30. CREATE TABLE t1 (
  31.   index1 smallint(6) default NULL,
  32.   nr smallint(6) default NULL,
  33.   KEY index1(index1)
  34. ) TYPE=MyISAM;
  35.  
  36. CREATE TABLE t2 (
  37.   nr smallint(6) default NULL,
  38.   name varchar(20) default NULL
  39. ) TYPE=MyISAM;
  40.  
  41. INSERT INTO t2 VALUES (1,'item1');
  42. INSERT INTO t2 VALUES (2,'item2');
  43.  
  44. # problem begins here!
  45. lock tables t1 write, t2 read;
  46. insert into t1 select 1,nr from t2 where name='item1';
  47. insert into t1 select 2,nr from t2 where name='item2';
  48. unlock tables;
  49. check table t1;
  50.  
  51. # Check error message
  52. lock tables t1 write;
  53. check table t2;
  54. unlock tables;
  55. drop table t1,t2;
  56.  
  57. #test to see if select will get the lock ahead of low priority update
  58. connect (locker,localhost,root,,);
  59. connect (reader,localhost,root,,);
  60. connect (writer,localhost,root,,);
  61.  
  62. connection locker;
  63. create table t1(n int);
  64. insert into t1 values (1);
  65. lock tables t1 write;
  66. connection writer;
  67. send update low_priority t1 set n = 4;
  68. connection reader;
  69. --sleep 2
  70. send select n from t1;
  71. connection locker;
  72. --sleep 2
  73. unlock tables;
  74. connection writer;
  75. reap;
  76. connection reader;
  77. reap;
  78. drop table t1;
  79.  
  80. connection locker;
  81. create table t1(n int);
  82. insert into t1 values (1);
  83. lock tables t1 read;
  84. connection writer;
  85. send update low_priority t1 set n = 4;
  86. connection reader;
  87. --sleep 2
  88. send select n from t1;
  89. connection locker;
  90. --sleep 2
  91. unlock tables;
  92. connection writer;
  93. reap;
  94. connection reader;
  95. reap;
  96. drop table t1;
  97.  
  98.